import 'dart:io';

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:rwini_edit/config/config.dart';
import 'package:rwini_edit/impl/file.dart';
import 'package:rwini_edit/impl/paser_ini.dart';

import 'logic.dart';

Widget buildLBox(HomeLogic logic) => Column(
      children: [
        Container(
          // height: 60,
          color: Colors.black12,
          child: Row(
            children: [
              TextButton(
                onPressed: () async {
                  String? a = await selectDir();
                  // conf.defaultPath = a ?? "~";
                  debugPrint("选择目录:$a");
                },
                child: Text(
                  "打开文件管理器",
                  style: TextStyle(fontSize: conf.fontsise * 0.8),
                ),
              ),
              TextButton(
                onPressed: () {},
                child: Text(
                  "刷新",
                  style: TextStyle(fontSize: conf.fontsise * 0.8),
                ),
              ),
            ],
          ),
        ),
        Expanded(
          child: Obx(() {
            return ListView.builder(
              shrinkWrap: true,
              // physics: const NeverScrollableScrollPhysics(),
              itemBuilder: (ctx, i) {
                var lname = logic.listdata[i].toString();
                var filename = "";
                if (Platform.isWindows) {
                  filename = lname.split("\\").last;
                } else {
                  filename = lname.split("/").last;
                }
                return ListTile(
                  title: TextButton(
                    onPressed: () {
                      logic.nowFile.value = lname;
                      // 点击 ini文件名
                      if (Platform.isWindows) {
                        conf.nowFilePath = null;
                      } else {
                        conf.nowFilePath = lname;
                      }
                      getinifile(lname);
                    },
                    child: Text(
                      filename,
                      style: TextStyle(fontSize: conf.fontsise * 0.8),
                    ),
                  ),
                );
              },
              itemCount: logic.listdata.length,
            );
          }),
        ),
      ],
    );
